﻿namespace ReactiveGraph.Core
{
    public class NodeEvent
    {
        public EventType Type { get; private set; }
        public EventSource Source { get; private set; }

        public static NodeEvent PropertyChanged(IReactiveNode node, IProperty property, object value)
        {
            return new NodeEvent
                       {
                           Source = EventSource.PropertyChanged(node, property, value),
                           Type = EventType.PropertyChange
                       };
        }

        public static NodeEvent NodeAdded(IReactiveNode added, IReactiveNode parent)
        {
            return new NodeEvent
                       {
                           Source = EventSource.NodeAdded(added, parent),
                           Type = EventType.DescendantAdded
                       };
        }

        public static NodeEvent NodeRemoved(IReactiveNode removed, IReactiveNode parent)
        {
            return new NodeEvent
                       {
                           Source = EventSource.NodeRemoved(removed, parent),
                           Type = EventType.DescendantRemoved
                       };
        }

        public static NodeEvent Wrap(NodeEvent nodeEvent, IReactiveNode node)
        {
            return new NodeEvent
                       {
                           Source = EventSource.Wrap(nodeEvent.Source, node),
                           Type = nodeEvent.Type
                       };
        }
    }
}